﻿Imports BE.BE
Imports BL.BL


Public Class frmCambiarClave

#Region "Atributos"


    Dim mClaveOK As Boolean

    Public ReadOnly Property claveOk As Boolean
        Get
            Return mClaveOK
        End Get
    End Property


#End Region


#Region "Métodos"


    Private Sub frmCambiarClave_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        mClaveOK = False
        'patentes del usuario logueado.
        Helper_FL.setearPermisos(frmPrincipal.usr, Me)
    End Sub


    Private Sub btnCambiarClave_Click(sender As Object, e As EventArgs) Handles btnCambiarClave.Click
        'se verifica si as dos claves ingresadas coinciden.
        If Me.txtNuevaClave.Text = Me.txtRepitaNuevaClave.Text Then
            'se graba la nueva password.
            mClaveOK = True
        Else
            MessageBox.Show("No coinciden.. Favor a ingresar la Clave y su verificación correctamente..")
            Me.txtNuevaClave.Text = ""
            Me.txtRepitaNuevaClave.Text = ""
            Me.txtNuevaClave.Focus()
        End If

        If mClaveOK = True Then

            If frmlogin.Visible = True Then
                Dim usr As New Usuario_BE
                usr = Usuario_BL.traerUsuario(frmlogin.txtNick.Text)
                usr.password = Me.txtNuevaClave.Text
                Usuario_BL.grabarNuevaPassword(usr)
                MessageBox.Show("Cambio de Clave exitoso.. vuelva a ingresar al sistema SEAS..")
                frmlogin.txtNick.Text = ""
                frmlogin.txtNick.Focus()
                frmlogin.txtPassword.Text = ""
            End If

            If frmPrincipal.Visible = True Then
                Dim usr As New Usuario_BE
                'usr = Usuario_BL.traerUsuario(frmPrincipal.nickensesion.ToString)
                usr = Usuario_BL.traerUsuario(frmPrincipal.usr.nick.ToString)
                usr.password = Me.txtNuevaClave.Text
                Usuario_BL.grabarNuevaPassword(usr)
                MessageBox.Show("Cambio de Clave exitoso.. vuelva a ingresar al sistema SEAS..")
            End If

            Me.Close()

        End If

    End Sub


    Private Sub btnCancelar_Click(sender As Object, e As EventArgs) Handles btnCancelar.Click
        If frmlogin.Visible = True Then
            frmlogin.txtNick.Text = ""
            frmlogin.txtPassword.Text = ""
            frmlogin.txtNick.Focus()
        End If
        Me.Close()
        Me.Dispose()
    End Sub


    Private Sub txtRepitaNuevaClave_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtRepitaNuevaClave.KeyPress
        'captura tecla Enter.
        If e.KeyChar = ChrW(Keys.Enter) Then
            Call btnCambiarClave_Click(Nothing, Nothing)
        End If
    End Sub


#End Region


#Region "Métodos auxiliares"

    Private Sub frmCambiarClave_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
        If e.KeyCode = Keys.F1 Then
            Help.ShowHelp(Me, Application.StartupPath & "\ayuda_SEAS.chm", "cambiarclave.htm")
        End If

    End Sub

#End Region


End Class